package com.skycong.hello77.amiebar.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;

import com.aspsine.swipetoloadlayout.OnLoadMoreListener;
import com.aspsine.swipetoloadlayout.OnRefreshListener;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.skycong.hello77.R;
import com.skycong.hello77.adapter.RecyclerAdapter;
import com.skycong.hello77.amiebar.adapter.AmieBarAdapter;
import com.skycong.hello77.amiebar.entity.AmieBar;
import com.skycong.hello77.amiebar.entity.AmieBar01;

import java.util.ArrayList;
import java.util.List;


/**
 * 阿米吧报表
 * Created by Kiki on 2018/5/31.
 */

public class AmieBarActivity extends Activity  implements OnLoadMoreListener,OnRefreshListener {
    private SwipeToLoadLayout swipeToLoadLayout;
    private RecyclerView swipe_target;
    private AmieBarAdapter recyclerAdapter;
    private List<AmieBar> data = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_amiebar);
        initData();
    }

    //初始化数据
    private void initData() {
        swipe_target = (RecyclerView) findViewById(R.id.swipe_target);
        //设置布局管理器方法，实现RecyclerView布局里面的内容显示方式
        //参数1，上下文，2，布局方式 3，布尔值是否反转，不反转，从上到下加载
        swipe_target.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL,false));
        recyclerAdapter = new AmieBarAdapter(this);
        swipe_target.setAdapter(recyclerAdapter);
        swipeToLoadLayout = (SwipeToLoadLayout) findViewById(R.id.swipeToLoadLayout);
        //上拉刷新
        swipeToLoadLayout.setOnRefreshListener(this);
        //上拉加载滑动事件
        swipeToLoadLayout.setOnLoadMoreListener(this);
        //获取后台数据
        refreshData();

    }
    //从后台获取数据

    private void refreshData() {
        data.addAll(AmieBar.getData());
        recyclerAdapter.setData(data);
        recyclerAdapter.notifyDataSetChanged();
    }


    @Override
    public void onLoadMore() {

    }

    @Override
    public void onRefresh() {

    }
}
